﻿//You are given an array of strings. Write a method that sorts the array by the length of its elements (the number of characters composing them).


using System;

namespace SortStringArray
{
    class SortStringArray
    {
        static void Main()
        {
            string[] stringArray = { "hasda", "haha", "lalsa", "hliorrl", "ldoskas" };

            SortBySize(stringArray);
        }

        static void SortBySize(string[] stringArray)
        {
            int n = stringArray.Length;
            int[] sizes = new int[n];

            //get the lenght of the elements in the array
            for (int i = 0; i < n; i++)
            {
                sizes[i] = stringArray[i].Length;
            }

            //sorting the array
            Array.Sort(sizes, stringArray);

            //print sorted array
            foreach (var element in stringArray)
            {
                Console.WriteLine(element);
            }
        }
    }
}
